﻿
#region

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.IO;

#endregion

namespace Soapi.Notify2
{
    [Serializable]
    public class SiteList : List<SiteListItem>
    {
        public void UpdateSiteIcons()
        {
            for (int i = 0; i < Count; i++)
            {
                var item = this[i];
                var client = new WebClient();

                byte[] buffer = client.DownloadData(item.Site.IconUrl);
                var image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = new MemoryStream(buffer);
                image.EndInit();
                image.Freeze();
                item.SiteIcon = new Image { Source = image };


            }
        }

        public SiteListItem Find(string apiEndpoint)
        {
            for (int i = 0; i < Count; i++)
            {
                if (this[i].ApiEndpoint == apiEndpoint)
                {
                    return this[i];
                }
            }
            return null;
        }
    }
}
